#include "GameEngine.h"
#include "HelpfulData.h"

GameEngine::GameEngine()
{
}

// Make sure release is called
GameEngine::~GameEngine()
{
	release();
}

// set up all game components
void GameEngine::initialize()
{
	// get sound engine reference
	pSound = Sound::getInstance();

	// set camera move speed
	m_cameraSpeed = 50.0f;

	// get input reference
	pInput = Input::getInstance();

	// get 2D graphics engine reference
	p2DEngine = DX2DEngine::getInstance();

	m_state = GAME;
	running = true;

	//  ****************************
	// put game stuff here
	//  ****************************
	//  ****************************
	FRect rect;
	rect.top = rect.left = 0;
	rect.bottom = rect.right = 32.0f;
	test.initialize(V2DF(300.0f,300.0f), L"images/test.png", rect, 1.0f);
	player.initialize(V2DF(300.0f,300.0f), L"images/test.png", rect, 1.0f);
	tWorld.initialize();
}

// update all game components
void GameEngine::update(float dT)
{
	// backup escape key
	if(pInput->keyDown(DIK_DELETE))
		running = false;

	// update based on given game state
	switch(m_state)
	{
	case MENU:
		break;
	case CLASS:
		break;
	case GAME:
		test.setPosition(pInput->getMousePos());
		player.Update(dT);
		tWorld.update(dT);
		break;
	case VICTORY:
		break;
	case DEAD:
		break;
	}
}

// render all game components
void GameEngine::render()
{
	// render the given objects for each state
	switch(m_state)
	{
	case MENU:
		break;
	case CLASS:
		break;
	case GAME:
		tWorld.render();
		test.render();
		player.render();
		break;
	case VICTORY:
	case DEAD:
		break;
	}
}

void GameEngine::drawText()
{
	switch(m_state)
	{
	case MENU:
		break;
	case CLASS:
		break;
	case GAME:
		break;
	case VICTORY:
	case DEAD:
		break;
	}
}

// safetly release all game components
void GameEngine::release()
{
	tWorld.release();
}

bool GameEngine::isRunning()
{
	return running;
}

void GameEngine::setRunning(bool a_run)
{
	running = a_run;
}

void GameEngine::setState(G_State state)
{
	m_state = state;
}